<script setup lang="ts">
import { ref } from 'vue'
const { data } = defineProps(['data'])
defineEmits(['click'])
const currenctSelectedColor = ref({})

const init = () => {
  data.list.map(e => {
    if (e.alias === data.recommand) currenctSelectedColor.value = e
  })
}
init()

const handleSelectColor = (buffer) => {
  currenctSelectedColor.value = buffer
  // emits
}
</script>
<template>
  <div class="color-picker-container">
    <div class="main-title">{{ data.title }}</div>
    <div class="related-txt">{{ data.sub }}</div>

    <div class="selected-color">
      {{ currenctSelectedColor.name }}<span v-if="currenctSelectedColor.alias === data.recommand">{{ $t('reserve_page.recommanded') }}</span>
    </div>
    <div class="colors-container">
      <div
        :class="['color-item', currenctSelectedColor.alias === item.alias ? 'color-item-active' : '']"
        v-for="item,index in data.list"
        @click="handleSelectColor(item)">
        <div class="color-display-block" :style="{ background: item.background }"></div>
      </div>
    </div>
  </div>
</template>
<style lang="less" scoped>
.color-picker-container {
  .main-title {
    font-weight: bold;
  }
  .related-txt {
    color: #999999;
  }
  .selected-color {}
  .colors-container {
    display: flex;
    .color-item {
      border-radius: 50%;
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      transition: all, 300ms;
      // border: 1px solid transparent;
      .color-display-block {
        border-radius: 50%;
      }
    }
    .color-item-active {
      border: 1px solid var(--color-main)
    }
  }
}
// Mobile
@media screen and (max-width: 767px) {
  .color-picker-container {
    .main-title {
      font-size: 20px;
    }
    .related-txt {
      font-size: 14px;
    }
    .selected-color {
      margin-top: 20px;
      font-size: 14px;
    }
    .colors-container {
      margin-top: 10px;
      gap: 10px;
      .color-item {
        width: 40px;
        height: 40px;
        border-width: 1px;
        .color-display-block {
          width: 32px;
          height: 32px;
        }
        &:hover {
          border: 1px solid var(--color-main)
        }
      }
      .color-item-active {
        border-width: 1px;
      }
    }
  }
}

// Tablet
@media screen and (max-width: 1023px) and (min-width: 768px) {
  .color-picker-container {
    .main-title {
      font-size: 20px;
    }
    .related-txt {
      font-size: 14px;
    }
    .selected-color {
      margin-top: 20px;
      font-size: 14px;
    }
    .colors-container {
      margin-top: 10px;
      gap: 10px;
      .color-item {
        width: 40px;
        height: 40px;
        border-width: 1px;
        .color-display-block {
          width: 32px;
          height: 32px;
        }
        &:hover {
          border: 1px solid var(--color-main)
        }
      }
      .color-item-active {
        border-width: 1px;
      }
    }
  }
}

// Desktop
@media screen and (min-width: 1024px) {
  .color-picker-container {
    .main-title {
      font-size: 20Px;
    }
    .related-txt {
      font-size: 14Px;
    }
    .selected-color {
      margin-top: 20Px;
      font-size: 14Px;
    }
    .colors-container {
      margin-top: 10Px;
      gap: 10Px;
      .color-item {
        width: 40Px;
        height: 40Px;
        cursor: pointer;
        border-width: 1Px;
        .color-display-block {
          width: 32Px;
          height: 32Px;
        }
        &:hover {
          border: 1Px solid var(--color-main)
        }
      }
      .color-item-active {
        border-width: 1Px;
      }
    }
  }
}
</style>